using System.Security.Cryptography;

namespace SharpObjects.Cryptography.Asymmetric
{
	/// <summary>
	/// Summary description for RsaProvider.
	/// </summary>
	public class RsaProvider : IAsymmetricCryptoProvider
	{
		protected RSACryptoServiceProvider m_provider = null;
		protected bool m_bOAEPPadding = false;
		protected bool m_bHidePrivateKey = false;

		public RsaProvider()
		{
			m_provider = new RSACryptoServiceProvider();
		}

		public RsaProvider(RSAParameters parameters)
		{
			m_provider.ImportParameters(parameters);
		}

		public bool OAEPPadding { get { return m_bOAEPPadding; } set { m_bOAEPPadding = value; } }
		public bool HidePrivateKey { get { return m_bHidePrivateKey; } set { m_bHidePrivateKey = value; } }

		//#region ICryptoProvider Members


		public byte [] Encrypt(byte [] data)
		{
			return m_provider.Encrypt(data, m_bOAEPPadding);
		}

		public byte [] Decrypt(byte [] data)
		{
			return m_provider.Decrypt(data, m_bOAEPPadding);
		}

		public ICryptoKey CryptoKey 
		{
			get
			{
				RsaKey key = new RsaKey(m_provider.ExportParameters(! m_bHidePrivateKey));
				return (ICryptoKey)key;
			}
			set
			{
				RsaKey key = (RsaKey)value;
				m_provider.ImportParameters(key);
			}
		}

		//#endregion
	}
}
